#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   16:50
# Author     : Y4
# Site       : 
# File       : 006 进程之间的通讯.py
# Software   : PyCharm

from multiprocessing import Queue,Process
from time import sleep

# q = Queue(5)
# q.put('a')
# q.put('b')
# q.put('c')
# q.put('d')
# q.put('e')
# print(q.qsize())
#
# if not q.full():                    # 判断队列是否已满
#     q.put('f',timeout=3)            # 如果Queue满了则只能等待,除非有空地,则添加成功
# else:
#     print('队列已满')
#
#
# if not q.empty():                   # 判断队列是否为空
#     print(q.get())
# else:
#     print("空队列")



# print("--"*50)




def download(q):
    images = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg']
    for i in images:
        print('正在下载,{}'.format(i))
        sleep(1)
        q.put(i)


def getfile(q):
    while True:
        try:
            file = q.get(timeout=5)
            print('{}文件保存成功'.format(file))
        except:
            print('全部保存完毕')
            break


if __name__ == '__main__':
    q = Queue(5)
    p1 = Process(target=download,args=(q,))
    p2 = Process(target=getfile,args=(q,))

    p1.start()
    p1.join()           # 让主线程让步

    p2.start()
    p2.join()           # 让主线程让步



    print('0000')








